﻿DROP TRIGGER IF EXISTS  `pk_friend_link_log`;
CREATE  TRIGGER `pk_friend_link_log` AFTER INSERT ON `open_friend_link`
  FOR EACH ROW BEGIN
dECLARE pkf varchar(50) DEFAULT "";
sELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="friend_link";
if pkf <> "friend_link" then
  INSERT INTO open_pk_log SET pk_from = 'friend_link', pk_id = NEW.link_id;
eLSE
   update open_pk_log SET pk_id = NEW.link_id WHERE pk_from = 'friend_link';
end if;
end;